#include<iostream>
#include<string>
#include<cstring>
#include<queue>
using namespace std;
string s[35];int visited[35];
int count=0;
int difference(string a,string b){
    int len=a.size();
    int diff=0;
    for(int i=0;i<len;i++){
        if(a[i]!=b[i]){
            diff++;
        }
    }
    return diff;
}
struct Pos{
    int index,steps;
    Pos(){};
    Pos(int ii,int ss):index(ii),steps(ss){};
};
queue<Pos> q;
void bfs(){
    memset(visited,0,sizeof(visited));
    Pos start,goal,temp;
    start=Pos(0,1);
    visited[0]=1;
    q.push(start);
    while(!q.empty()){
        temp=q.front();
        if(temp.index==count){
            break;
        }
        q.pop();
        for(int i=1;i<=count;i++){
            if(visited[i]==0&&difference(s[i],s[temp.index])==1){
                visited[i]=1;
                q.push(Pos(i,temp.steps+1));
            }
        }
    }
    if(q.empty()){
        cout<<0<<endl;
    }else{
        cout<<temp.steps<<endl;
    }
    
}
int main(){
    string sn;
    cin>>s[0]>>sn;
    while(cin>>s[++count]);
    s[count]=sn;
    bfs();
    return 0;
}